<template>
</template>
<script>
import * as dd from 'dingtalk-jsapi'

export default {
  data() {
    return {
      platForm: ''
    }
  },
  mounted() {
    let pathname = window.location.search
    let pathArr = pathname.split('&')
    this.platForm = pathArr[0].split('=')[1]
    let that = this

    dd.ready(function () {
      dd.runtime.permission
        .requestAuthCode({
          corpId: 'ding8bac6beff1d2d841', // 企业id
          onSuccess: function (info) {
            try {
              let code = info.code // 通过该免登授权码可以获取用户身份
              that
                .$http({
                  url: '/api/gateway/basemgt-emp/login/transtalent',
                  method: 'post',
                  data: {
                    code: code,
                    platForm: that.platForm
                  }
                })
                .then(data => {
                  if (data.code == 200) {
                    window.location.href = decodeURIComponent(data.data)
                  } else {
                    if (data.msg) {
                      that.$toast(data.msg)
                    } else {
                      that.$toast(data.message)
                    }
                  }
                })
            } catch (error) {
              if (data.msg) {
                that.$toast(data.msg)
              } else {
                that.$toast(data.message)
              }
            }
          },
          onFail: function (err) {
            that.$toast(err)
          }
        })
        .catch(err => {
          console.log(err)
          alert(err)
        })
    })
  }
}
</script>

